//#include<bits/stdc++.h>
#include <iostream>
#include<algorithm>
#include<vector>
#include<set>
typedef unsigned long long ull;
using namespace std;
vector<set<int>>vec;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, k;
	cin >> n;
	vec.resize(n+1);
	for (int i = 1;i <= n;i++) {
		int l;
		cin >> l;
		for (int j = 0;j < l;j++) {
			int tmp;
			cin >> tmp;
			vec[i].insert(tmp);
		}
	}
	cin >> k;
	for (int i = 0;i < k;i++) {
		int a, b;
		cin >> a >> b;
		vector<int> intersection_result;
		set_intersection(vec[a].begin(), vec[a].end(),
			vec[b].begin(), vec[b].end(),
			back_inserter(intersection_result));

		printf("%.2f%%\n", intersection_result.size() * 100.0 / 
			(vec[a].size() + vec[b].size() - intersection_result.size()));
	}
	return 0;
}